package com.youlu.campus.service.utils;

import com.yuelin.infrastructure.quantum.hessian.Guard;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WebTokenUtils {
    public static final String delimiter = "^^";

    public static final String signKey = "(#IKJ&HGH^666u";

    public static String signToken(String openId) {
        log.info(":>>> 处理签名:{}", openId);
        return openId + delimiter + Guard.sign(openId, signKey);
    }

    public static String getOpenIdByMiniToken(String miniToken) {
        int idx = miniToken.indexOf(delimiter);
        if (idx <= 0) {
            log.error("miniToken格式错误 miniToken:{}", miniToken);
            return null;
        }
        String openId = miniToken.substring(0, idx);
        return openId;
    }
}
